package com.ruoyi.busi.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.busi.domain.vo.BusiCompanyEfVo;
import com.ruoyi.busi.domain.bo.BusiCompanyEfBo;
import com.ruoyi.busi.service.IBusiCompanyEfService;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 碳排放Controller
 *
 * @author ruoyi
 * @date 2024-12-02
 */
@Validated
@Api(value = "碳排放控制器", tags = {"碳排放管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/busi/companyEf")
public class BusiCompanyEfController extends BaseController {

    private final IBusiCompanyEfService iBusiCompanyEfService;

    /**
     * 查询碳排放列表
     */
    @ApiOperation("查询碳排放列表")
    @PreAuthorize("@ss.hasPermi('busi:companyEf:list')")
    @GetMapping("/list")
    public TableDataInfo<BusiCompanyEfVo> list(@Validated(QueryGroup.class) BusiCompanyEfBo bo) {
        return iBusiCompanyEfService.queryPageList(bo);
    }

    /**
     * 导出碳排放列表
     */
    @ApiOperation("导出碳排放列表")
    @PreAuthorize("@ss.hasPermi('busi:companyEf:export')")
    @Log(title = "碳排放", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public void export(@Validated BusiCompanyEfBo bo, HttpServletResponse response) {
        List<BusiCompanyEfVo> list = iBusiCompanyEfService.queryList(bo);
        ExcelUtil.exportExcel(list, "碳排放", BusiCompanyEfVo.class, response);
    }

    /**
     * 获取碳排放详细信息
     */
    @ApiOperation("获取碳排放详细信息")
    @PreAuthorize("@ss.hasPermi('busi:companyEf:query')")
    @GetMapping("/{id}")
    public AjaxResult<BusiCompanyEfVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iBusiCompanyEfService.queryById(id));
    }

    /**
     * 新增碳排放
     */
    @ApiOperation("新增碳排放")
    @PreAuthorize("@ss.hasPermi('busi:companyEf:add')")
    @Log(title = "碳排放", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public AjaxResult<Void> add(@Validated(AddGroup.class) @RequestBody BusiCompanyEfBo bo) {
        return toAjax(iBusiCompanyEfService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改碳排放
     */
    @ApiOperation("修改碳排放")
    @PreAuthorize("@ss.hasPermi('busi:companyEf:edit')")
    @Log(title = "碳排放", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public AjaxResult<Void> edit(@Validated(EditGroup.class) @RequestBody BusiCompanyEfBo bo) {
        return toAjax(iBusiCompanyEfService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除碳排放
     */
    @ApiOperation("删除碳排放")
    @PreAuthorize("@ss.hasPermi('busi:companyEf:remove')")
    @Log(title = "碳排放" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iBusiCompanyEfService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
